package com.io.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式工具类
 * Created by yangyx on 2016/7/28.
 */
public class ValidationUtils {

        public final static String RegExpIpAddress="^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])" +
                "\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)" +
                "\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)" +
                "\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$";

        public final static String RegExpVin = "^[A-Z|0-9]{17}$";
        public final static String RegExpTid = "^[A-Z|0-9]{10}$";
        public final static String RegExpPassword = "^[a-z|A-Z|0-9]{10}$";

        static Pattern patternIpAddress;
        static Pattern patternVin;
        static Pattern patternTid;
        static Pattern patternPassword;

    static {
        patternIpAddress=Pattern.compile(RegExpIpAddress);
        patternVin=Pattern.compile(RegExpVin);
        patternTid=Pattern.compile(RegExpTid);
        patternPassword=Pattern.compile(RegExpPassword);
    }

    public static boolean isValidIpAddress(String ipAddress) {
        Matcher m = patternIpAddress.matcher(ipAddress);
        return m.find();
    }
    public static boolean isValidVin(String vin){
        Matcher m = patternVin.matcher(vin);
        return m.find();
    }
    public static boolean isValidTid(String tid){
        Matcher m = patternTid.matcher(tid);
        return m.find();
    }
    public static boolean isValidPassword(String password){
        Matcher m = patternPassword.matcher(password);
        return m.find();
    }


}
